#coding=utf-8
'''
# @Name:tools
# @author:mysouil
# @Description:
# @DATE:2022/9/24 1:28
# @Modified By:
'''
import re

def mobile(mobile_str):
    """ 检验手机号格式 :param mobile_str: str 被检验字符串 :return: mobile_str """
    
    if re.match(r'^1[3789]\d{9}$', mobile_str):
        return mobile_str
    else:
        raise ValueError('{} is not a valid mobile'.format(mobile_str))
    
def regex(pattern):
    '''
    正则校验
    :param pattern:str 正则表达式
    :return:返回
    '''
    
    def validate(value_str):
        '''
        根据自定义的正则，校验字符串
        :param value_str:校验的值
        :return:
        '''

        if re.match(pattern,value_str):
            return value_str
        else:
            raise ValueError('{} is not a valid params.'.format(value_str))
    
    return validate


def check_email(email):
    '''
    校验邮箱格式
    :param email:str 邮箱字符串
    :return:email
    '''
    
    if re.match(r'^([a-z0-9_-]+)@([\da-z-]+)\.([a-z]{2,6})$', email):
        return email
    else:
        raise ValueError('{} is not a valid email'.format(email))